home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / amivogl-1.03.lzh / vogl / drivers / ibmpc / cga.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-29  |  2.5 KB  |  174 lines

  1. #include    "vogl.h"
  2. #include    <stdio.h>
  3. #ifdef TC
  4. #include    <dos.h>
  5. #define        _dos_allocmem    allocmem
  6. #define        _dos_freemem    freemem
  7. #endif
  8.  
  9. #define        C_PIX_ASPECT    2.4
  10. #define        NPARA    (640 * 200 / 16)
  11.  
  12. static    unsigned    allocated = 0, old_mode;
  13. static    unsigned    char    *backbuf;
  14.  
  15. extern    unsigned    int    _buffer_segment;
  16. extern    unsigned    int    _buffer_offset;
  17. extern    unsigned    int    _cur_color;
  18. static    unsigned    int    save_seg;
  19.  
  20. extern    int    cga_clear(),
  21.         cga_frontbuf(),
  22.         cga_swapbuf(),
  23.         _cga_set_buffer(),
  24.         pc_fill(),
  25.         pc_font(),
  26.         pc_getkey(),
  27.         pc_checkkey(),
  28.         pc_locator(),
  29.         pc_string(),
  30.         setmode();
  31.  
  32.  
  33. static int
  34. cga_init()
  35. {
  36.     vdevice.sizeX = 199 * C_PIX_ASPECT;
  37.     vdevice.sizeY = 199;
  38.     vdevice.sizeSx = 639;
  39.     vdevice.sizeSy = 199;
  40.     vdevice.depth = 1;
  41.     _buffer_segment = 0xB800;
  42.     _buffer_offset = 0;
  43.     _cur_color = 1;
  44.     old_mode = setmode(6);
  45.     pc_locinit(vdevice.sizeSx, vdevice.sizeSy);
  46.     return (1);
  47. }
  48.  
  49. /* 
  50.  * cga_vclear
  51.  *
  52.  *    Just clears the current viewport.
  53.  */
  54. static
  55. cga_vclear()
  56. {
  57.     int     x[4], y[4];
  58.  
  59.     if (vdevice.maxVx != vdevice.sizeSx
  60.         || vdevice.maxVy != vdevice.sizeSy
  61.         || vdevice.minVx != vdevice.sizeSx
  62.         || vdevice.minVy != vdevice.sizeSy) {
  63.         x[0] = x[3] = vdevice.minVx;
  64.         y[0] = y[1] = vdevice.maxVy;
  65.         y[2] = y[3] = vdevice.minVy;
  66.         x[1] = x[2] = vdevice.maxVx;
  67.  
  68.         pc_fill(5, x, y);
  69.     } else {
  70.         cga_clear();
  71.     }
  72.  
  73.     return(0);
  74. }
  75.  
  76.  
  77. /*
  78.  * cga_exit
  79.  *
  80.  *    Sets the display back to text mode.
  81.  */
  82. static
  83. cga_exit()
  84. {
  85.     unshowmouse();
  86.     if (allocated)
  87.         _dos_freemem(save_seg);
  88.  
  89.     setmode(old_mode);
  90.     return (1);
  91. }
  92.  
  93. static
  94. cga_draw(x, y)
  95.     int    x, y;
  96. {
  97.     cgaline(vdevice.cpVx, vdevice.sizeSy - vdevice.cpVy, x, vdevice.sizeSy - y, _cur_color);
  98.     vdevice.cpVx = x;
  99.     vdevice.cpVy = y;
  100.  
  101.     return(0);
  102. }
  103.  
  104. static
  105. cga_char(c)
  106.     int    c;
  107. {
  108.     cgachar(c, vdevice.cpVx, vdevice.sizeSy - vdevice.cpVy, _cur_color, 1 - _cur_color);
  109.     return(0);
  110. }
  111.  
  112. static
  113. cga_color(i)
  114.     int    i;
  115. {
  116.     _cur_color = (i > 0 ? 1 : 0);
  117.  
  118.     return(0);
  119. }
  120.  
  121. static
  122. cga_backbuf()
  123. {
  124.     if (!allocated) {
  125.         if (_dos_allocmem(NPARA, &_buffer_segment) != 0)
  126.             verror("cga_backbuf: couldn't allocate space");
  127.  
  128.         allocated = 1;
  129.         save_seg = _buffer_segment;
  130.     }
  131.     return(1);
  132. }
  133.  
  134. static    int
  135. noop()
  136. {
  137.     return (-1);
  138. }
  139.  
  140. static DevEntry cgadev = {
  141.     "cga",
  142.     "large",
  143.     "small",
  144.     cga_backbuf,
  145.     cga_char,
  146.     pc_checkkey,
  147.     cga_vclear,
  148.     cga_color,
  149.     cga_draw,
  150.     cga_exit,
  151.     pc_fill,
  152.     pc_font,
  153.     cga_frontbuf,
  154.     pc_getkey,
  155.     cga_init,
  156.     pc_locator,
  157.     noop,
  158.     pc_string,
  159.     cga_swapbuf
  160. };
  161.  
  162. /*
  163.  * _cga_devcpy
  164.  *
  165.  *    copy the pc device into vdevice.dev.
  166.  */
  167. _cga_devcpy()
  168. {
  169.     vdevice.dev = cgadev;
  170.  
  171.     return(0);
  172. }
  173.  
  174.